﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.WebSocket.RPC.DTO;
using PServiceBus.Services.Web.DTO;
using PServiceBus.Services.Gateway.Runtime;
using System.Linq.Expressions;

namespace PServiceBus.WebSocket.RPC.Runtime {
    public partial class WebSocketMessageBus {

        private void CreateSubscriber(NameObject info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.CreateSubscriber(info.name);
        }

        private void ChangeSubscriberDurability(SubscriptionInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.ChangeSubscriberDurability(info);
        }

        private void Subscribe(SubscriptionInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.Subscribe(info);
        }

        private void Update(SubscriptionInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.Update(info);
        }

        private void UnSubscribe(SubscriptionInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.UnSubscribe(info);
        }

        private void AddTransport(SubscriptionInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.AddTransport(info);
        }

        private void DeleteTransport(SubscriptionInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.DeleteTransport(info);
        }

        private Subscriber SelectSubscriber(NameObject info) {
            if (info == null) throw new ArgumentNullException("info");
            return MessageBus.SelectSubscriber(info.name);
        }

        private Topic SelectTopic(NameObject info) {
            if (info == null) throw new ArgumentNullException("info");
            return MessageBus.SelectTopic(info.name);
        }

        private bool Ping() {
            return MessageBus.Ping();
        }

        private void DeleteSubscriber(NameObject info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.DeleteSubscriber(info.name);
        }

        private void DeleteTopic(NameObject info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.DeleteTopic(info.name);
        }

        private void RegisterTopic(TopicInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            MessageBus.RegisterTopic(info);
        }

        private void PublishTopic(PublishTopicInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            info.Headers = info.Headers ?? new Dictionary<string, string>();
            if (!String.IsNullOrWhiteSpace(ClientIpAddress))
                info.Headers["PSB-ClientIpAddress"] = ClientIpAddress;
            MessageBus.PublishTopic(info);
        }

        private IEnumerable<Topic> GetTopics() {
            return MessageBus.GetTopics();
        }

        private void Disconnect(NameObject info) {
            if (info == null) throw new ArgumentNullException("info");
            //TODO: make use of info object
            MessageBus.Dispose();
        }
    }
}
